#ifndef NETWORK_COMMON_H
#define NETWORK_COMMON_H

#include <QtNetwork/QNetworkInterface>

QString getHostIpAddress()
{
    QString strIpAddress;
    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();

    for(int i=0; i<ipAddressesList.size(); i++)
    {
        if(ipAddressesList.at(i) != QHostAddress::LocalHost &&
           ipAddressesList.at(i).toIPv4Address())
        {
            strIpAddress = ipAddressesList.at(i).toString();
            break;
        }
    }
    if(strIpAddress.isEmpty())
        strIpAddress = QHostAddress(QHostAddress::LocalHost).toString();
    return strIpAddress;
}

QString getHostMacAddress()
{
    QString strMacAddr;
    QList<QNetworkInterface> nets = QNetworkInterface::allInterfaces();
    for(int i=0; i<nets.size(); i++)
    {
        if(nets[i].flags().testFlag(QNetworkInterface::IsUp) &&
           nets[i].flags().testFlag(QNetworkInterface::IsRunning) &&
           !nets[i].flags().testFlag(QNetworkInterface::IsLoopBack))
        {
            strMacAddr = nets[i].hardwareAddress();
            break;
        }
    }
    return strMacAddr;
}

#endif // NETWORK_COMMON_H
